package com.example.flutter_android_connect

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.PluginRegistry
/**
 * 记住 「plugins.flutter.io/custom_platform_view」 ，这个字符串在 Flutter 中需要与其保持一致。
 */
class MyPlugin : FlutterPlugin {

    override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
        val messenger: BinaryMessenger = binding.binaryMessenger
        binding
                .platformViewRegistry
                .registerViewFactory("plugins.flutter.io/custom_platform_view", MyFlutterViewFactory(messenger))
    }

    companion object {
        @JvmStatic
        fun registerWith(registrar: PluginRegistry.Registrar) {
            registrar
                    .platformViewRegistry()
                    .registerViewFactory("plugins.flutter.io/custom_platform_view",MyFlutterViewFactory(registrar.messenger()))
        }
    }

    override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {

    }
}
//class MyPlugin :FlutterPlugin{
//    override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
//        val messenger:BinaryMessenger=binding.binaryMessenger
//        binding.platformViewRegistry.registerViewFactory("plugins.flutter.io/custom_platform_view",MyFlutterViewFactory(messenger))
//    }
//
//    override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
//
//    }
////    伴生对象
//    companion object{
////    静态方法的实现
//        @JvmStatic
//        fun registerWith(registry: PluginRegistry.Registrar){
//            registry.platformViewRegistry()
//                    .registerViewFactory("plugins.flutter.io/custom_platform_view",MyFlutterViewFactory(registry.messenger()))
//        }
//    }
//
//}